//
//  AppDelegate.m
//  Test1
//
//  Created by KelvinYeung on 15/7/8.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "AppDelegate.h"
#import "KVNHomeNavigationController.h"
#import "KVNHomeViewController.h"
#import "KVNMediaViewerViewController.h"
#import "KVNMineViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //初始化数据存储
    self.dataStoreEngine = [[KVNDataStoreEngine alloc]init];
    
    
    //NSDictionary *requestHeader = @{@"Content-Type":@"application/json;encoding:utf-8"};
    
    self.httpRequestEngine = [[KVNHttpRequestEngine alloc] initWithHostName:@"112.74.96.195" apiPath:@"/user_mobile" customHeaderFields:nil];
    [self.httpRequestEngine useCache];
    
    [UIImageView setDefaultEngine:self.httpRequestEngine];
    
    //初始化window
    self.window =[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    
    //主页
    KVNHomeViewController *homeView = [[KVNHomeViewController alloc] init];
    
    //导航控制器
    KVNHomeNavigationController *nav = [[KVNHomeNavigationController alloc] initWithRootViewController:homeView];
    nav.navigationBar.barTintColor =[UIColor colorWithRed:202/225.000 green:57/225.000 blue:24/225.000 alpha:1];
    nav.tabBarItem.title = @"首页";
    nav.tabBarItem.image = [UIImage imageNamed:@"tab_home"];


    
    //动态
    UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    //webView.scrollView.alwaysBounceVertical = NO;
    [(UIScrollView *)[[webView subviews] objectAtIndex:0] setBounces:NO];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://112.74.96.195/user_mobile/web/index.do"]];
    [webView loadRequest:request];
    
    UIView *statusBarView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication]statusBarFrame]];
    statusBarView.backgroundColor = [UIColor colorWithRed:202/225.000 green:57/225.000 blue:24/225.000 alpha:1];
    
    UIViewController *webViewController = [[UIViewController alloc] init];
    webViewController.view.backgroundColor =[UIColor whiteColor];
    webViewController.navigationController.navigationBar.barStyle =UIStatusBarStyleBlackOpaque;
    [webViewController.view addSubview:statusBarView];
    [webViewController.view addSubview:webView];
    
    UIBarButtonItem *dynamicBarButtonItem = [[UIBarButtonItem alloc] init];
    [dynamicBarButtonItem setTitle:@"动态"];
    dynamicBarButtonItem.tintColor = [UIColor whiteColor];
    [webViewController.navigationItem setLeftBarButtonItem:dynamicBarButtonItem];
    
    UINavigationController *dynamicNavigationController = [[UINavigationController alloc] initWithRootViewController:webViewController];
    dynamicNavigationController.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
    dynamicNavigationController.tabBarItem.title = @"动态";
    dynamicNavigationController.tabBarItem.image = [UIImage imageNamed:@"tab_dynamic"];
    dynamicNavigationController.navigationBar.barTintColor =[UIColor colorWithRed:202/225.000 green:57/225.000 blue:24/225.000 alpha:1];
    
    

    
    
    
    
    //我的
    
    KVNMineViewController *mineViewController = [[KVNMineViewController alloc] init];
    mineViewController.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    UINavigationController *mineNavigationController = [[UINavigationController alloc] initWithRootViewController:mineViewController];
    mineNavigationController.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
    mineNavigationController.tabBarItem.title = @"我的";
    mineNavigationController.tabBarItem.image = [UIImage imageNamed:@"tab_mine"];
    mineNavigationController.navigationBar.barTintColor =[UIColor colorWithRed:202/225.000 green:57/225.000 blue:24/225.000 alpha:1];
    
    //tab 主页  动态 我的
    UITabBarController *mainTabBarController =  [[UITabBarController alloc] init];
    mainTabBarController.tabBar.tintColor = [UIColor redColor];
    
    
    [mainTabBarController addChildViewController:nav];
    [mainTabBarController addChildViewController:dynamicNavigationController];
    [mainTabBarController addChildViewController:mineNavigationController];
    
    
    self.window.rootViewController = mainTabBarController;
    
    
       
    
    //必须要以下方法才会显示界面
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
